package com.financing.wap.service.impl;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.financing.wap.dao.IFpOrderRebateDao;
import com.financing.wap.service.IRebateService;
import com.financing.wap.util.DateUtil;
import com.financing.wap.vo.MyAccountVo;

/**
 * 返利(佣金计算)
 * @author luohanbin
 *
 */
@Service("rebateService")
public class RebateServiceImpl extends BaseServiceImpl implements
		IRebateService {
	
	@Autowired
	private IFpOrderRebateDao fpOrderRebateDao;

	//今日平台产生总佣金，累计收入， 近一个月收入， 帐号余额
	public MyAccountVo calcMyAccounts(Integer faId){
		//step1 计算平台今日总佣金
		Map<String, Object> paramMap = new HashMap<String, Object>(3);
		paramMap.put("startDate", DateUtil.getDateStarting(new Date()));
		BigDecimal todayAllRebates = fpOrderRebateDao.calcAllRebatesByDate(paramMap);  //今天所有返利
		logger.info("today total rebates: " + todayAllRebates);
		
		//累计收入
		paramMap.remove("startDate");
		paramMap.put("faId", faId);
		BigDecimal faAllRebates = fpOrderRebateDao.calcAllRebatesByDate(paramMap);  //FA所有返利
		logger.info("FA total rebates: " + faAllRebates);
		
		//近一个月收入
		paramMap.put("startDate", DateUtil.getDateStarting(DateUtil.addMonth(new Date(), -1)));  //按照天
		paramMap.put("faId", faId);
		BigDecimal faLatestMonthRebates = fpOrderRebateDao.calcAllRebatesByDate(paramMap);  //今天所有返利
		logger.info("current month rebates: " + faLatestMonthRebates);
		
		//帐号余额
//		int accountMoney = 100000; //TODO 写死 
		MyAccountVo vo = new MyAccountVo();
//		vo.setAccountMoney(accountMoney);
		vo.setFaAllRebates(faAllRebates);
		vo.setFaLatestMonthRebates(faLatestMonthRebates);
		vo.setTodayAllRebates(todayAllRebates);
		return vo;
//		paramMap.put("startDate", value);
	}
}
